package schoolmath.web.services;

import org.apache.commons.codec.binary.Hex;

import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashTools {

	public static String generateMd5(String message) {
		MessageDigest messageDigest = null;

		try {
			messageDigest = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			return "";
		}

		messageDigest.reset();
		messageDigest.update(message.getBytes(Charset.forName("UTF8")));
		byte[] resultByte = messageDigest.digest();
		String result = new String(Hex.encodeHex(resultByte));

		return result;
	}

}
